﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web.UI;
using System.ComponentModel;

namespace Ue.Qcdz.UI.Controls
{
    public class LoadFiles : Control, INamingContainer
    {
        protected override void Render(HtmlTextWriter writer)
        {
            this.RenderFiles(writer, this.StyleFiles, "\n<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" />", "~/Themes/zh-cn/Style/");

            this.RenderFiles(writer, this.AdminStyleFiles, "\n<link rel=\"stylesheet\" href=\"{0}\" type=\"text/css\" />", "~/Admin/Themes/Style/");

            this.RenderFiles(writer, this.JavaScriptFiles, "\n<script src=\"{0}\" type=\"text/javascript\"></script>", "~/Support/JavaScript/");
        }
        private void RenderFiles(HtmlTextWriter writer, string files, string format, string pathPrefix)
        {
            if (string.IsNullOrEmpty(files))
            {
                return;
            }

            var fileArray = files.Split(',').Where(item => !string.IsNullOrEmpty(item)).ToList();
            foreach (var file in fileArray)
            {
                writer.Write(string.Format(format, this.ResolveUrl(Path.Combine(pathPrefix, file))));
            }
        }

        /// <summary>
        /// （前台）样式表文件名,多个名之间用","隔开
        /// </summary>
        [Description("加载 /Themes/zh-cn/Style/ 文件夹中的 css 文件")]
        public string StyleFiles { get; set; }

        /// <summary>
        /// （后台）样式表文件名,多个名之间用","隔开
        /// </summary>
        [Description("加载/Admin/Themes/Style/文件夹中的 css文件")]
        public string AdminStyleFiles { get; set; }

        /// <summary>
        /// Js文件名,多个名之间用","隔开
        /// </summary>
        [Description("加载 /Support/JavaScript/ 文件夹中的js文件")]
        public string JavaScriptFiles { get; set; }

    }
}
